<?php

/**
 * This is the model class for table "tbl_onderzoek".
 *
 * The followings are the available columns in table 'tbl_onderzoek':
 * @property integer $id
 * @property string $naam
 * @property integer $maker_id
 * @property integer $is_public
 * @property integer $stap_id
 *
 * The followings are the available model relations:
 * @property TblGebruiker $maker
 * @property TblStap $stap
 * @property TblResultaat[] $tblResultaats
 * @property TblStap[] $tblStaps
 */
class Onderzoek extends ExtendedActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Onderzoek the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
        
        public function toonVolledigOnderzoek(){
            //geeft het volledige overzicht
            
        }
        
        public function startOnderzoek(){
            //toont de beginpositie van het onderzoek
            
        }
        
       /*
        public function getConnectieWaarden(){
            //geef alle connectiewaarden van het onderzoek
            $stappen = $this->getStappen();
            //van elke stap de connecties
            $connecties = array();
            foreach($stappen as $stap){
                array_push($connecties, $stap->getChildConnecties());
            }
            //van elke connectie de waarde
            $waarden = array();
            foreach($connecties as $conn){
                array_push($waarden, $conn->waarde);
            }
            return $connecties;
        }
        * 
        */
        
        public function getStappen(){
            $criteria = new CDbCriteria;
            $criteria->condition='onderzoek_id=:onderzoek_id'; // and or
            $criteria->params=array(':onderzoek_id'=>$this->id);
            $stappen = Stap::model()->findAll($criteria);
            return $stappen;
        }
        
        public function getMainStap(){
            $stap = Stap::model()->findByPk($this->stap_id);
            return $stap;
        }
        
        public function getFullViewMainStap(){
            $mainstap = $this->getMainStap();
            $waarde = $mainstap->getWaarde()->waarde;
            return array('id'=>$mainstap->id,'waarde'=>$waarde);
        }

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_onderzoek';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('naam, stap_id', 'required'),
			array('maker_id, is_public, stap_id', 'numerical', 'integerOnly'=>true),
			array('naam', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, naam, maker_id, is_public, stap_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'maker' => array(self::BELONGS_TO, 'TblGebruiker', 'maker_id'),
			'stap' => array(self::BELONGS_TO, 'TblStap', 'stap_id'),
			'tblResultaats' => array(self::HAS_MANY, 'TblResultaat', 'onderzoek_id'),
			'tblStaps' => array(self::HAS_MANY, 'TblStap', 'onderzoek_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'naam' => 'Naam',
			'maker_id' => 'Maker',
			'is_public' => 'Is Public',
			'stap_id' => 'Stap',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('naam',$this->naam,true);
		$criteria->compare('maker_id',$this->maker_id);
		$criteria->compare('is_public',$this->is_public);
		$criteria->compare('stap_id',$this->stap_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}